package com.ymt.bpm.web.action.mobile;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
public class DingtalkController {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private Environment env;

    @RequestMapping(path="/pages/mobile/dd/index")
    public ModelAndView indexDd(HttpServletRequest request) {
        try {
            request.getSession();   //avoid IllegalStateException
        } catch (Exception e) {
            return null;
        }
        if (log.isDebugEnabled()) {
            log.debug("indexDd /pages/mobile/dd/index");
        }
        String[] profile = env.getActiveProfiles();
        String productionVersion = env.getProperty("bpmp.production-version", "0");
        String cdn = env.getProperty("bpmp.cdn", "/bpmp-resources");
        ModelAndView view = new ModelAndView("mobile/dd/index");
        view.addObject("profile", profile[0]);
        view.addObject("productionVersion", productionVersion);
        view.addObject("cdn", cdn);
        //Dingtalk debug base url
        view.addObject("baseUrlOverrideForDebug", env.getProperty("dingtalk.debug-base-url", ""));
        return view;
    }
}
